package org.springblade.modules.material.strategy.impl;

import org.springblade.common.enums.library.QuestionType;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.modules.library.vo.QuestionOptionVO;
import org.springblade.modules.material.entity.PaperAnswerEntity;
import org.springblade.modules.material.entity.PaperAnswerOptionEntity;
import org.springblade.modules.material.strategy.CalculateScoreStrategy;
import org.springblade.modules.material.vo.PaperAnswerVO;
import org.springblade.modules.material.vo.PaperDetailsRelatedVO;
import org.springblade.modules.material.vo.PaperReleaseDetailVO;

import java.util.List;

/**
 * @Author: junxin
 * @Description: 计算判断题
 */
public class CalculateJudgeQuestion implements CalculateScoreStrategy {

	@Override
	public Integer calculateScore(List<PaperReleaseDetailVO> paperReleaseDetailVOList,
								  List<PaperAnswerOptionEntity> paperAnswerOptionEntityList,Long  paperAnswerId,Integer multipleScoreSetting) {
		int score=0;
		for (PaperReleaseDetailVO paperReleaseDetailVO:paperReleaseDetailVOList){
			//选项内容
			List<QuestionOptionVO> questionOptionList = paperReleaseDetailVO.getQuestionOptionList();
			for (QuestionOptionVO questionOptionVO:questionOptionList){
				if (questionOptionVO.getChoice()==1){
					PaperAnswerOptionEntity paperAnswerOptionEntity=new PaperAnswerOptionEntity();
					paperAnswerOptionEntity.setAnswerId(paperAnswerId);
					paperAnswerOptionEntity.setUserId(AuthUtil.getUserId());
					paperAnswerOptionEntity.setChecked(questionOptionVO.getId());
					paperAnswerOptionEntity.setReleaseDetailId(paperReleaseDetailVO.getId());
					paperAnswerOptionEntity.setValue(0);
					paperAnswerOptionEntity.setQuestionId(questionOptionVO.getQuestionBankId());
					paperAnswerOptionEntity.setQuestionType(QuestionType.JUDGE.getCode());
					if (questionOptionVO.getIsRight()==1 ) {
						score+=paperReleaseDetailVO.getValue();
						paperAnswerOptionEntity.setValue(paperReleaseDetailVO.getValue());
					}
					paperAnswerOptionEntityList.add(paperAnswerOptionEntity); //保存用户的作答选项
					break; //判断题可以结束
				}
			}
		}



		return score;
	}
}
